﻿using System.Windows.Controls;
using System.Windows.Navigation;
using WinSource.ViewModel;

namespace WinSource.Views
{
    public partial class WritersPage
    {
        #region Fields

        private WritersViewModel _writersViewModel;

        #endregion

        #region Constructor

        public WritersPage()
        {
            InitializeComponent();

            _writersViewModel = DataContext as WritersViewModel;
        }

        #endregion

        #region PhoneApplicationPage Overrides

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (NavigationContext.QueryString.ContainsKey("Writer"))
            {
                string writer = NavigationContext.QueryString["Writer"];

                switch (writer)
                {
                    case "Joe Fedewa":
                        pivot.SelectedIndex = 0;
                        break;

                    case "Ashley King":
                        pivot.SelectedIndex = 1;
                        break;
                }
            }
        }

        #endregion

        private void PivotSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            switch (pivot.SelectedIndex)
            {
                case 0:
                    _writersViewModel.CurrentWriter = _writersViewModel.WriterJoe;
                    break;

                case 1:
                    _writersViewModel.CurrentWriter = _writersViewModel.WriterAshley;
                    break;
            }
        }

        #region Event Handlers

        #endregion
    }
}